from django.db import models

# Create your models here.

class Base(models.Model):
    create_time=models.DateTimeField(auto_now_add=True,verbose_name='创建时间')
    updata_time=models.DateTimeField(auto_now=True,verbose_name='更新时间')
    class Meta:
        abstract=True #抽象基类

class User(Base):
    nickname=models.CharField(max_length=20,verbose_name='昵称',unique=True)
    status=(
        (1,'离婚'),
        (2,'未婚'),
        (3,'丧偶')
    )
    state=models.IntegerField(choices=status,verbose_name='个人状态')
    is_vip=models.BooleanField(default=False,verbose_name='is_vip')
    greet=models.BooleanField(default=True,verbose_name='是否可以打招呼,默认为可打')
    is_freeze=models.BooleanField(default=False,verbose_name='账号是否被冻结')
    password=models.CharField(max_length=255,verbose_name='密码',default='')
    gender_choice=(
        (1,'男'),
        (2,'女')
    )
    gender=models.IntegerField(choices=gender_choice,verbose_name='性别',default=1)
    age=models.CharField(max_length=30,verbose_name='年龄',default='')
    site=models.CharField(max_length=40,verbose_name='地区',default='')
    height=models.IntegerField(verbose_name='身高',default=0)
    edu=models.CharField(max_length=10,verbose_name='学历',default='')
    occ=models.CharField(max_length=20,verbose_name='职业',default='')
    income=models.CharField(max_length=10,verbose_name='月收入',default='')
    emile=models.EmailField(max_length=50,verbose_name='邮箱',default='')
    img=models.ImageField(upload_to='user',verbose_name='用户头像',default='user/weixin.jpg')
    friend_show=models.CharField(max_length=255,default='',verbose_name='交友宣言')
    def __str__(self):
        return self.nickname
    class Meta:
        db_table='user'


#留言表
class Leave_mes(Base):
    be_leave_user=models.ForeignKey(User,on_delete=models.SET_NULL,null=True,blank=True,related_name='be_leave_user')
    leave_user=models.ForeignKey(User,on_delete=models.SET_NULL,null=True,blank=True,related_name='leave_user')
    message=models.TextField()
    status=(
        (1,'已读'),
        (2,'未读'),
        (3,'不感兴趣')
    )
    state=models.IntegerField(choices=status,verbose_name='信息类型')
    def __str(self):
        return self.from_user.nickname+':'+self.rece_user.nickname
    class Meta:
        db_table='leave_mes'
#约会表
class Date(Base):
    date_start_time=models.DateField(auto_now_add=True,verbose_name='约会发起时间')
    date_success_time=models.DateField(auto_now=True,verbose_name='约会成功时间')
    site=models.CharField(max_length=50,verbose_name='约会地点')
    status=(
        (1,'共享晚餐'),
        (2,'浪漫电影'),
        (3,'相约出游'),
        (4,'喝茶小叙'),
        (5,'欢唱k歌')
    )
    state=models.IntegerField(choices=status,verbose_name='约会类型')
    invite_user=models.ForeignKey(User,on_delete=models.CASCADE,related_name='invite_user',verbose_name='约会发起者')
    be_invite_user=models.ForeignKey(User,on_delete=models.SET_NULL,null=True,blank=True,related_name='be_invite_user')
    pay_choice=(
        (1,'发起者买单'),
        (2,'匹配者买单'),
        (3,'AA制'),
        (4,'面议')
    )
    pay_user=models.IntegerField(choices=pay_choice,verbose_name='谁来买单')
    budget=models.CharField(max_length=20,verbose_name='费用预算')
    brief=models.CharField(max_length=190,verbose_name='约会简介')
    is_success=models.BooleanField(default=False,verbose_name='此次约会是否成功')
    def __str__(self):
        return self.from_user.nickname
    class Meta:
        db_table='date'

#约会分享表
class Date_share(Base):
    date=models.ForeignKey(Date,on_delete=models.CASCADE,verbose_name='分享约会')
    img=models.TextField(null=True,verbose_name='约会图片')
    from_user=models.ForeignKey(User,on_delete=models.CASCADE,verbose_name='分享者')
    title=models.CharField(max_length=30,verbose_name='标题')
    is_consent=models.BooleanField(default=False,verbose_name='另一方是否同意')
    content=models.TextField(verbose_name='分享内容')
    def __str__(self):
        return self.from_user.nickname+':'+self.date.site
    class Meta:
        db_table='data_share'
#恋爱学堂
class Love_school(Base):
    title=models.CharField(max_length=30,verbose_name='恋爱标题')
    from_user=models.ForeignKey(User,on_delete=models.SET_NULL,null=True,blank=True,verbose_name='分享者')
    content=models.TextField(verbose_name='内容')
    classify=(
        (1,'爱情故事'),
        (2,'恋爱宝典'),
        (3,'新手上路'),
        (4,'婚姻法规'),
        (5,'合作共赢')
    )
    love_classify=models.IntegerField(choices=classify,verbose_name='故事分类')
    def __str__(self):
        return self.title
    class Meta:
        db_table='love_school'
#用户关系表
class Relation(Base):
    user_one=models.ForeignKey(User,on_delete=models.CASCADE,verbose_name='用户一',related_name='user_one')
    user_two=models.ForeignKey(User,on_delete=models.CASCADE,verbose_name='用户二',related_name='user_two')
    love_choice=(
        (1,'热恋'),
        (2,'分手'),
        (3,'已婚'),
        (4,'无关系')
    )
    love=models.IntegerField(choices=love_choice,default=4,verbose_name='恋爱字段')
    look_choice=(
        (1,'user_one看过user_two'),
        (2,'互相看过'),
        (3,'无关系')
    )
    look=models.IntegerField(choices=look_choice,default=3,verbose_name='看过字段')
    shield_choice=(
        (1,'user_one屏蔽user_two'),
        (2,'互相屏蔽'),
        (3,'user_one取消屏蔽user_two'),
        (4,'无关系')
    )
    shield=models.IntegerField(choices=shield_choice,default=4,verbose_name='屏蔽字段')
    gift_choice = (
        (1, 'user_one送礼物user_two'),
        (2, '互相送过'),
        (3,'无关系')
    )
    gift = models.IntegerField(choices=shield_choice, default=3, verbose_name='礼物字段')
    follow_choice=(
        (1,'user_one关注user_two'),
        (2, '互相关注'),
        (3, 'user_one取关user_two'),
        (4, '无关系')
    )
    follow=models.IntegerField(choices=follow_choice,default=4,verbose_name='关注')
    class Meta:
        unique_together=(('user_one','user_two','love'),('user_one','user_two','look'),
                         ('user_one','user_two','shield'),('user_one','user_two','gift'),
                         ('user_one','user_two','follow'))
        db_table='user_relation'
    def __str__(self):
        return self.user_one.nickname+':'+self.user_two.nickname


#打招呼表
class Greet(Base):
    lick_user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='被打招呼者',related_name='lick_user')
    init_user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='打招呼者',related_name='init_user')
    is_may=models.BooleanField(default=False,verbose_name='送礼物才能打招呼,或者两人同时看过')
    class Meta:
        unique_together = (('rece_user', 'from_user'))
    def __str__(self):
        return self.from_user.nickname+':'+self.rece_user.nickname
    class Meta:
        db_table='greet'


#聊天表
class Chat(Base):
    rece_user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='接受消息者',related_name='rece_user')
    from_user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='发送消息者',related_name='from_user')
    rece_mes=models.ForeignKey(User,on_delete=models.CASCADE,verbose_name='用户接受的消息',related_name='rece_mes')
    from_mes=models.ForeignKey(User,on_delete=models.CASCADE,verbose_name='用户发送的消息',related_name='from_mes')
    def __str__(self):
        return self.from_user.nickname
    class Meta:
        db_table='chat'


#签到表
class Sign(Base):
    sign_user=models.ForeignKey(User,on_delete=models.CASCADE,verbose_name='签到用户')
    sign_day=models.IntegerField(default=0,verbose_name='签到天数')
    def __str__(self):
        return self.sign_user.nickname+':'+self.sign_day
    class Meta:
        db_table='sign'

#礼物表
class Gift(Base):
    gift_name=models.CharField(max_length=10,verbose_name='礼物名称')
    gift_price=models.DecimalField(max_digits=6,decimal_places=2,verbose_name='礼物价格')
    gift_img=models.ImageField(upload_to='gift/',verbose_name='礼物图标')
    def __str__(self):
        return self.gift_name
    class Meta:
        db_table='gift'

#用户礼物表
class User_gift(Base):
    user=models.ForeignKey(User,on_delete=models.CASCADE,verbose_name='所属用户')
    gift=models.ForeignKey(Gift,on_delete=models.CASCADE,verbose_name='拥有礼物')
    num=models.IntegerField(default=0,verbose_name='礼物数量')
    def __str__(self):
        return self.user.nickname+':'+self.gift.gift_name+':'+self.num
    class Meta:
        db_table='user_gift'

#举报表
class Report(Base):
    report_user=models.ForeignKey(User,on_delete=models.CASCADE,verbose_name='举报人',related_name='report_user')
    be_report_user=models.ForeignKey(User,on_delete=models.CASCADE,verbose_name='被举报人',related_name='be_report_user')
    cause_choice=(
        (1,'涉黄涉暴涉黑'),
        (2,'散播谣言'),
        (3,'存在恶意欺骗行为')
    )
    cause=models.IntegerField(choices=cause_choice,verbose_name='举报原因')
    is_succee=models.BooleanField(default=False,verbose_name='举报是否成功')
    def __str__(self):
        return self.report_user.nickname+':'+self.be_report_user.nickname+':'+self.cause
    class Meta:
        db_table='report'

#红娘表
class Matchmaker(Base):
    name=models.CharField(max_length=20,verbose_name='名字')
    phone=models.CharField(max_length=30,verbose_name='电话号')
    address=models.CharField(max_length=50,verbose_name='地址')
    centont=models.CharField(max_length=190,verbose_name='简介')
    number=models.IntegerField(default=0,verbose_name='牵线人数')
    grade_choice=(
        (1,'一级红娘'),
        (2,'二级红娘'),
        (3,'新手红娘')
    )
    grade=models.IntegerField(choices=grade_choice,verbose_name='红娘等级')
    price=models.DecimalField(max_digits=8,decimal_places=2,verbose_name='价格')
    img=models.ImageField(upload_to='matchmaker/',verbose_name='红娘图片')
    is_ok=models.BooleanField(default=False,verbose_name='是否实名认证')
    def __str__(self):
        return self.name
    class Meta:
        db_table='matchmaker'

#用户委托红娘表
class Entrust(Base):
    entrust_user=models.ForeignKey(User,on_delete=models.CASCADE,verbose_name='委托用户',related_name='entrust_user')
    matchmaker=models.ForeignKey(Matchmaker,on_delete=models.CASCADE,verbose_name='红娘')
    be_entrust_user=models.ForeignKey(User,on_delete=models.SET_NULL,null=True,blank=True,
                                      related_name='be_entrust_user',verbose_name='被委托用户')
    class Meta:
        unique_together=(('entrust_user','matchmaker','be_entrust_user'))
        db_table='entrust'
    def __str__(self):
        return self.entrust_user.nickname+':'+self.matchmaker
#评论表
class Comment(Base):
    commenter=models.ForeignKey(User,on_delete=models.CASCADE,related_name='commenter',verbose_name='评论者')
    be_commenter=models.ForeignKey(User,on_delete=models.CASCADE,related_name='be_commenter',verbose_name='被评论者')
    content=models.CharField(max_length=190,verbose_name='评论内容')
    class Meta:
        db_table='comment'
    def __str__(self):
        return self.be_commenter.nickname+':'+self.content

#圈子表
class Circle(Base):
    sponsor=models.ForeignKey(User,on_delete=models.SET_NULL,null=True,blank=True,related_name='sponsor',verbose_name='圈子发起者')
    name=models.CharField(max_length=20,verbose_name='圈子名称')
    number=models.IntegerField(verbose_name='圈子人数')
    content=models.CharField(max_length=190,verbose_name='圈子简介')
    img=models.ImageField(upload_to='circle/',verbose_name='圈子图片')
    user=models.ManyToManyField(User,through='User_detail',through_fields=('circle','user'),verbose_name='圈子人员')
    class Meta:
        db_table='circle'
    def __str__(self):
        return self.sponsor
#圈子个人详情
class User_detail(Base):
    circle=models.ForeignKey(Circle,on_delete=models.CASCADE,verbose_name='指向圈子')
    user=models.ForeignKey(User,on_delete=models.CASCADE,verbose_name='圈子人员',related_name='user')
    invite=models.ForeignKey(User,on_delete=models.SET_NULL,null=True,blank=True,verbose_name='邀请人员',related_name='invite')
    join_time=models.DateField(auto_now_add=True,verbose_name='加入时间')
    class Meta:
        db_table='user_detail'
    def __str__(self):
        return self.circle.name+':'+self.user.nickname



